import request, { BASE_URL } from '@/utils/request';
import type { ISearchParams, IUser } from '@/types/request';
import type { TransformValueOfUser } from '@/types/table-transform';

// 登录接口
export function adminLogin(data: { phone: string; password: string }) {
  return request('/login', {
    method: 'POST',
    data,
    baseURL: BASE_URL + '/api/user/v1',
  });
}

// 用户数据接口
export function checkAdminRole() {
  return request('/detail', {
    baseURL: BASE_URL + '/api/user/v1',
  });
}

// 搜索用户
export function searchUser(options: Omit<ISearchParams, 'total'>) {
  let params = {
    page: options.page,
    size: options.size,
  };
  
  return request<IUser, true>(
    `/user${options?.condition ? '/' + options.condition : ''}`,
    {
      params,
    }
  );
}

// 删除用户
export function deleteUser(id: string) {
  return request(`/user/${id}`, { method: 'DELETE' });
}

// 更新用户信息
export function updateUser(data: TransformValueOfUser) {
  return request(`/user/${data.id}`, {
    method: 'PUT',
    data: { updated_details: data },
  });
}
